package com.copa.l1523;

/**
 * @author copa
 * @createDate 2022-08-25 14:48
 * @function 公式法
 */
public class Test1 {

    // 这种方法是可以，显然是超时，不会让你来这样干了（暴力法）
//    public int countOdds(int low, int high) {
//        int count = 0;
//        for (int i = low; i <= high; i++) {
//            if (i % 2 == 1) {
//                count++;
//            }
//        }
//        return count;
//    }

    public int countOdds(int low, int high) {
        if (low % 2 == 0) {
            return (high - low + 1) / 2;
        }
        return (high - low) / 2 + 1;
    }

    public static void main(String[] args) {
        int low = 2;
        int high = 8;
        System.out.println(new Test1().countOdds(low, high));
    }
}
